class Solution {
private:
	stack<int> st;
public:
    vector<int> canSeePersonsCount(vector<int>& heights) {
		vector<int>ans(heights.size(), 0);
		st.push(heights[heights.size() - 1]);
		for(int i = heights.size() - 2; i >= 0; i--){
			int temp = 1;
			while(!st.empty() && st.top() < heights[i]){
				st.pop();
				temp++;
			}
			ans[i] = temp;
			st.push(heights[i]);
		}
		return ans;
    }
};
